//************************************************************************
// usbint.c
//************************************************************************

/** @addtogroup MMPF_USB
@{
*/

//************************************************************************
// usbint.c
//************************************************************************
//extern  MMP_ULONG   dwTotalSec;

//extern  MMP_ULONG   USBEP0TxBufAddr;
//extern  MMP_ULONG   CBWRxBufAddr;
//extern  MMP_ULONG   CSWTxBufAddr;

extern  MMP_USHORT  USBEP0TxCnt;

//extern  MMP_ULONG   USBEP0TxAddr;
//extern  MMP_ULONG   USBEP0RxAddr;

extern  MMP_USHORT  USBConfigDescLen;
#if SUPPORT_HID_FUNC
extern  MMP_USHORT  USBReportDescLen;
#endif
extern  MMP_UBYTE   USBInPhase;
extern  MMP_UBYTE   USBOutPhase;
extern  MMP_UBYTE   USBDevAddr;
extern  MMP_UBYTE   USBRequestType;
extern  MMP_UBYTE   USBMSDCPhase;
//extern  MMP_UBYTE   USBVendCmd;
extern  MMP_UBYTE   USBConfig;
extern  MMP_UBYTE   USBInterface;
extern  MMP_UBYTE   USBEndpoint;
extern  MMP_UBYTE   USBAlterSetting;

extern  MMP_USHORT  USBFrameNum;
extern  MMP_UBYTE   USBDevice;

//extern  MMP_ULONG   USBBulkTxAddr;
//extern  MMP_UBYTE   PCC_Interface_Num;

extern  MMP_UBYTE   USBCmd;
extern  MMP_UBYTE   glUsbApplicationMode;
//extern  MMP_UBYTE   USBMSDCStatus;
//extern  MMP_UBYTE   SMWPFlag;
//extern  MMP_UBYTE   UpdateFlag;
//extern  MMP_UBYTE   ReadReg;
extern  MMP_USHORT   USBConfig1Len;
//extern  MMP_UBYTE   USBConfig2Len;

#if (SUPPORT_PCCAM_FUNC==1)
extern MMP_UBYTE    PCCamModeEnable;
#endif

void usb_ep0_setup_done(void);
void usb_ep0_in_done(void);
void usb_ep0_out_done(void);
void usb_ep1_done(void);
void usb_ep2_done(void);
void usb_ep3_done(void);
void usb_plug_det(void);
void usb_reset_event(void);
void usb_sof_event(void);
void usb_error(void);
void usb_ep0_error(void);
void usb_ep1_error(void);
void usb_ep2_error(void);
void usb_ep3_error(void);
void usb_ep4_error(void);
void clear_ep1_sequence(void);
void clear_ep2_sequence(void);
void clear_ep3_sequence(void);
void usb_ep2_ack(void);
void usb_ep2_nak(void);
void usb_bulk_tx_start(void);
void usb_bulk_txrx_start(void);
void class_request_setup(void);
void class_request_in(void);
void class_request_out(void);
void class_reset(void);
void class_in_reset(void);
void class_out_reset(void);
void class_get_max_lun(void);
void class_in_get_max_lun(void);
void class_out_get_max_lun(void);
//void usb_ep0_null_out(void);
#define usb_ep0_null_out()
void usb_ep0_null_in(void);
void usb_ep0_xbyte_in(void);
void usb_ep0_in(void);
void usb_reset_module3(void);
void EnableEx(MMP_UBYTE endpoint);

#if (SUPPORT_MTP_FUNC==1)||(SUPPORT_DPS_FUNC==1)
void class_in_mtp_get_device_status(void);
void class_out_mtp_get_device_status(void);
void class_in_mtp_cancel_request(void);
void class_out_mtp_cancel_request(void);
void class_mtp_cancel_request(void);
void class_mtp_get_device_status(void);
#endif

//************************************************************************
// usbmsdc.c
//************************************************************************
void msdc_ep1_cbw_phase(void);
void msdc_ep1_tx_phase(void);
void msdc_ep1_csw_phase(void);
void msdc_ep1_tx_done(void);
void msdc_cmd_start(void);
void msdc_ep2_cbw_phase(void);
void msdc_ep2_rx_phase(void);
void msdc_ep2_csw_phase(void);
void msdc_ep2_rx_done(void);
void msdc_set_rx_cmd_buffer(void);
void msdc_set_rx_data_buffer(void);
void msdc_set_tx_buffer(void);
void msdc_rx_cbw(void);
void msdc_set_csw_header(MMP_UBYTE cCSWStatus);
void msdc_tx_csw(void);
void msdc_process_command(void);
void msdc_cmd_formatunit(void);
void msdc_cmd_rezero(void);
void msdc_cmd_verify(void);
void msdc_cmd_seek(void);
void msdc_cmd_senddiagnostic(void);
void msdc_cmd_startstopunit(void);
void msdc_cmd_writeandverify(void);
void msdc_cmd_testunitready(void);
void msdc_cmd_inquiry(void);
void msdc_cmd_readformatcapacity(void);
void msdc_cmd_readcapacity(void);
void msdc_cmd_modeselect(void);
void msdc_cmd_preventallowmediumremoval(void);
void msdc_cmd_modesense1A(void);
void msdc_cmd_modesense5A(void);
void msdc_cmd_requestsense(void);
void msdc_read_data(void);
void msdc_ep1_csw_phase_start(void);
void msdc_ep1_csw_phase_end(void);
void msdc_ep2_csw_phase_start(void);
void usb_ep1_stall(void);
void msdc_cmd_write(void);
void msdc_cmd_read10(void);
void msdc_cmd_write10(void);
void msdc_cmd_write12(void);
void msdc_set_sense_data(MMP_UBYTE errCode, MMP_UBYTE SenseKey, MMP_ULONG info, MMP_UBYTE asc, MMP_UBYTE ascq,
                         MMP_UBYTE snsKeyInfo0, MMP_UBYTE snsKeyInfo1);
MMP_USHORT msdc_check_card_status(void);
MMP_USHORT msdc_check_card_exist(void);
MMP_USHORT msdc_check_card_wp(void);
void msdc_check_card_size(MMP_ULONG *sectCount, MMP_ULONG *sectSize);
extern  void A810L_SetMSDCIntToHost(void);

//************************************************************************
// usbstd.c
//************************************************************************
void std_request_setup(void);
void std_request_in(void);
void std_request_out(void);
void send_getstatus_data(void);
void std_setup_getstatus(void);
void std_in_getstatus(void);
void std_out_getstatus(void);
void send_clrfeature_data(void);
void std_setup_clearfeature(void);
void std_in_clearfeature(void);
void std_out_clearfeature(void);
void send_setfeature_data(void);
void std_setup_setfeature(void);
void std_in_setfeature(void);
void std_out_setfeature(void);
void std_setup_setaddress(void);
void std_in_setaddress(void);
void std_out_setaddress(void);
void std_setup_setdescriptor(void);
void std_in_setdescriptor(void);
void std_out_setdescriptor(void);
void std_setup_getconfiguration(void);
void std_in_getconfiguration(void);
void std_out_getconfiguration(void);
void std_setup_setconfiguration(void);
void std_in_setconfiguration(void);
void std_out_setconfiguration(void);
void std_setup_getinterface(void);
void std_in_getinterface(void);
void std_out_getinterface(void);
void std_setup_setinterface(void);
void std_in_setinterface(void);
void std_out_setinterface(void);
void std_setup_synchframe(void);
void std_in_syncframe(void);
void std_out_syncframe(void);
void std_setup_getdevicedescriptor(void);
void std_in_getdevicedescriptor(void);
void std_out_getdevicedescriptor(void);
void std_setup_getstringdescriptor(void);
void std_in_getstringdescriptor(void);
void std_out_getstringdescriptor(void);
void std_setup_getconfigurationdescriptor(void);
void std_in_getconfigurationdescriptor(void);
void std_out_getconfigurationdescriptor(void);

//************************************************************************
// usbvend.c
//************************************************************************
void vendor_request_setup(void);
void vendor_request_in(void);
void vendor_request_out(void);
void VendorOutProcess(void);
void usb_check(void);
void VendorSetupProcess(void);
void VendorInProcess(void);
void SetBuffAddr(void);
void SetRxBuffAddr(void);
void usb_get_buff(void);
void usb_receive_buff(void);
void vendor_set_buff_access_addr(void);
void vendor_get_buff_access_size(void);
void vendor_set_resolution(void);
void vendor_set_device_mode(void);
void vendor_update_flash_ATF_area(void);


//************************************************************************
// usbdescr.c
//************************************************************************
#if (SUPPORT_UVC_FUNC==1)
extern  MMP_UBYTE DEVICE_QUALIFIER_DESCRIPTOR_DATA0[0x0A];
extern  MMP_UBYTE DEVICE_QUALIFIER_DESCRIPTOR_DATA1[0x0A];
extern  MMP_UBYTE   HS_CONFIG_DESCRIPTOR_DATA0[0x002a];
#ifdef UVC_MJPEG
extern  MMP_UBYTE   HS_CONFIG_DESCRIPTOR_DATA1[0x0190];
#else
extern  MMP_UBYTE   HS_CONFIG_DESCRIPTOR_DATA1[];
extern  MMP_UBYTE   HS_CONFIG_DESCRIPTOR_DATA2[];
#endif
extern  MMP_UBYTE   DEVICE_DESCRIPTOR_DATA0[0x12];
#ifdef UVC_MJPEG
extern MMP_UBYTE    CONFIG_DESCRIPTOR_DATA1[0x0190];
#else
extern MMP_UBYTE    CONFIG_DESCRIPTOR_DATA1[];
#endif

extern  MMP_UBYTE   HIDREPORT_DESCRIPTOR[0x1a];
extern  MMP_UBYTE   DEVICE_DESCRIPTOR_DATA1[0x12];
extern  MMP_UBYTE   DEVICE_QUALIFIER_DESCRIPTOR_DATA2[0x0A];
extern  MMP_UBYTE   HS_CONFIG_DESCRIPTOR_DATA2[0x20];
extern  MMP_UBYTE   DEVICE_DESCRIPTOR_DATA2[0x12];
extern  MMP_UBYTE   CONFIG_DESCRIPTOR_DATA2[0x20];
extern  MMP_UBYTE   DEVICE_QUALIFIER_DESCRIPTOR_DATA3[0x0A];
extern  MMP_UBYTE   HS_CONFIG_DESCRIPTOR_DATA3[0x20];
extern  MMP_UBYTE   DEVICE_DESCRIPTOR_DATA3[0x12];
extern  MMP_UBYTE   CONFIG_DESCRIPTOR_DATA3[0x20];

extern  MMP_UBYTE   CONFIG_DESCRIPTOR_DATA5[0x43];
extern  MMP_UBYTE   DEVICE_DESCRIPTOR_DATA5[0x12];
extern  MMP_UBYTE   HS_CONFIG_DESCRIPTOR_DATA5[0x43];
extern  MMP_UBYTE   DEVICE_QUALIFIER_DESCRIPTOR_DATA5[0x0A];

extern  MMP_UBYTE   LANGUAGE_ID_DATA[0x04];
extern  MMP_UBYTE   MANUFACTURER_STRING_DATA[];
extern  MMP_UBYTE   PRODUCT_STRING_DATA[];
extern  MMP_UBYTE   SERIALNUMBER_STRING_DATA[];
extern  MMP_UBYTE   PRODUCT_STRING2_DATA[];
#if SUPPORT_HID_FUNC
extern  MMP_UBYTE   HID_REPORT_DSCR_DATA[];
#endif

#else

extern  MMP_UBYTE   DEVICE_DESCRIPTOR_DATA1[0x12];
extern  MMP_UBYTE   CONFIG_DESCRIPTOR_DATA1[0x20];
extern  MMP_UBYTE   DEVICE_DESCRIPTOR_DATA2[0x12];
extern  MMP_UBYTE   CONFIG_DESCRIPTOR_DATA2[0x20];
extern  MMP_UBYTE  DEVICE_DESCRIPTOR_DATA3[0x12];
extern  MMP_UBYTE  CONFIG_DESCRIPTOR_DATA3[0x20];
extern  MMP_UBYTE  DEVICE_DESCRIPTOR_DATA4[0x12];
extern  MMP_UBYTE  CONFIG_DESCRIPTOR_DATA4[0x27];
extern  MMP_UBYTE  OS_STRING_DATA[0x12];
extern  MMP_UBYTE  EXTENDED_CONFIGURATION_DATA[0x28];
extern  MMP_UBYTE   LANGUAGE_ID_DATA[0x04];
extern  MMP_UBYTE   MANUFACTURER_STRING_DATA[0x1E];
extern  MMP_UBYTE   PRODUCT_STRING_DATA[0x1E];
extern  MMP_UBYTE   FRAME0_STRING_DATA[0x0E];
extern  MMP_UBYTE   FRAME1_STRING_DATA[0x0E];
#endif
extern  MMP_UBYTE   INQUIRY_TABLE_START[][0x24];
extern  MMP_UBYTE   MODE_SENSE_TABLE_START[0x08];
extern  MMP_UBYTE   REQUEST_SENSE_TABLE1_START[0x12];
extern  MMP_UBYTE   REQUEST_SENSE_TABLE2_START[0x0E];
extern  MMP_UBYTE   MODE_SENSE_TABLE00_START[0x02];
extern  MMP_UBYTE   MODE_SENSE_TABLE1C_START[0x0C];
extern  MMP_UBYTE   MODE_SENSE_TABLE3F_START[0x44];
#if (SUPPORT_MTP_FUNC==1)||(SUPPORT_DPS_FUNC==1)
extern  MMP_UBYTE  DEVICE_DESCRIPTOR_DATA5[];
extern  MMP_UBYTE  CONFIG_DESCRIPTOR_DATA5[];
extern  MMP_UBYTE  SERIALNUMBER_STRING_DATA[];
#endif //#if (SUPPORT_MTP_FUNC==1)||(SUPPORT_DPS_FUNC==1)

//************************************************************************
// usbpub.c
//************************************************************************
void usb_desc_init(void);
MMP_ULONG USB_GET_SOF_NUM(void);
void usb_sw_enum(void);
void usb_ep_init(void);
void A810L_InitUSB(void);
void SPI_Write(MMP_UBYTE addr, MMP_USHORT data);

//************************************************************************
// usb_ctl.c
//************************************************************************
void MMPF_SetUSB(void);
void MMPF_SetPCCAMCompressBuf(unsigned int buf_addr, unsigned int buf_size);

/// @}
